package com.vanke.vms.management.action;

//import org.apache.struts2.json.annotations.JSON;

import com.vanke.vms.common.action.BaseAction;
import com.vanke.vms.common.domain.User;
import com.vanke.vms.management.service.RegisterService;

public class RegisterAction extends BaseAction {

	private static final long serialVersionUID = -2422245322357925318L;

	private String username;

	private String password;

	private String repeat_password;

	private String phone;

	private String name;

	private String job;

	private String grade;

	private RegisterService registerService;

	private User user;

	private String isDublicapted;

	public String register() {
		if(isDublipcated()){
			return null;
		}
		user = new User();
		user.setUsername(username);
		user.setName(name);
		user.setPassword(password);
		user.setGrade(Integer.parseInt(grade));
		user.setValidate(4);
		if(phone != null)
			user.setPhone(phone);
		if(job != null)
			user.setJob(job);
		registerService.registeUser(user);
		return SUCCESS;
	}

//	public String update() {
//		User user = (User) session.get("user");
//		user.setName(name);
//		user.setPassword(password);
//		user.setPhone(phone);
//		registerService.updateUser(user);
//		return SUCCESS;
//	}

	public boolean isDublipcated() {
		if (registerService.isDublipcated(username))
			return true;
		else {
			return false;
		}
	}
//	public String isDublipcated() {
//		if (registerService.isDublipcated(username))
//			this.setIsDublicapted("true");
//		else {
//			this.setIsDublicapted("false");
//		}
//		return JSON;
//
//	}

//	public String showRegister() {
//		return REGISTER;
//	}
//
//	public String showUpdate() {
//		if (session.get("user") == null) {
//			return LOGIN;
//		} else {
//			return UPDATE;
//		}
//	}
	
	public String getIsDublicapted() {
		return isDublicapted;
	}

	public void setIsDublicapted(String isDublicapted) {
		this.isDublicapted = isDublicapted;
	}

//	@JSON(serialize = false)
	public RegisterService getRegisterService() {
		return registerService;
	}

	public void setRegisterService(RegisterService registerService) {
		this.registerService = registerService;
	}

//	@JSON(serialize = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getJob() {
		return job;
	}

	public void setJob(String job) {
		this.job = job;
	}

	public String getRepeat_password() {
		return repeat_password;
	}
	
	public String getGrade() {
		return grade;
	}

	public void setGrade(String grade) {
		this.grade = grade;
	}

	public void setRepeat_password(String repeatPassword) {
		repeat_password = repeatPassword;
	}
}
